﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSharpStudy
{
    class DI_2
    {
        //public static void Main(string[] args)
        //{
        //    Role_DI_2 role=new Role_DI_2(){Name = "JAY"};
        //    role.Weapon=new WoodWeapon();
        //    Monster_DI_2 monster=new Monster_DI_2("半兽人",100);
        //    Monster_DI_2 monster2=new Monster_DI_2("黑龙",1000);

        //    role.Attrack(monster);
        //    role.Attrack(monster);
        //    role.Attrack(monster);
        //    role.Attrack(monster);

        //    role.Weapon = new MagicWeapon();
        //    role.Attrack(monster2);
        //    role.Attrack(monster2);
        //    role.Attrack(monster2);
        //    role.Attrack(monster2);
        //    role.Attrack(monster2);
        //    role.Attrack(monster2);
        //    role.Attrack(monster2);
        //    role.Attrack(monster2);
        //    Console.ReadLine();
        //}
    }

    /// <summary>
    /// 怪物类
    /// </summary>
    class  Monster_DI_2
    {
        /// <summary>
        /// 名字
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 血量
        /// </summary>
        private int HP { get; set; }

        public Monster_DI_2()
        {
        }

        public Monster_DI_2(string monsterName,int hp)
        {
            Name = monsterName;
            HP = hp;
        }

        /// <summary>
        /// 血量改变
        /// </summary>
        /// <param name="changeHp"></param>
        public void Notify(int changeHp)
        {
            HP += changeHp;
            
            if (HP<=0)
            {
                HP = 0;
                Console.WriteLine("怪物已死！");
            }
            Console.WriteLine(Name + "当前血量：" + HP);
        }
    }

    interface IAttrackStragey_DI_2
    {
        /// <summary>
        /// 攻击力
        /// </summary>
         int ATK { get; set; }
    
        /// <summary>
        /// 攻击
        /// </summary>
        /// <param name="monster"></param>
        void AttrackTarget(Monster_DI_2 monster);
    }

    /// <summary>
    /// 木剑
    /// </summary>
    class WoodWeapon:IAttrackStragey_DI_2
    {
        public int ATK { get; set; }

        public WoodWeapon()
        {
            ATK = 30;
        }

        public void AttrackTarget(Monster_DI_2 monster)
        {
            Console.WriteLine(monster.Name+"被木剑攻击，损失:"+ATK+"HP");
            monster.Notify(-ATK);
        }
    }

    /// <summary>
    /// 魔刃
    /// </summary>
    class MagicWeapon : IAttrackStragey_DI_2
    {
        public int ATK { get; set; }

        public MagicWeapon()
        {
            ATK = 50;
        }
        Random rm=new Random();
        public void AttrackTarget(Monster_DI_2 monster)
        {
            ATK = rm.NextDouble() > 0.5 ? 50 : 100;
            Console.WriteLine(monster.Name + "被魔刃攻击，损失:" + ATK + "HP");
            monster.Notify(-ATK);
        }
    }

    /// <summary>
    /// 角色
    /// </summary>
    class  Role_DI_2
    {
        /// <summary>
        /// 名字
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 武器
        /// </summary>
        public IAttrackStragey_DI_2 Weapon { get; set; }

        /// <summary>
        /// 攻击
        /// </summary>
        /// <param name="monster"></param>
        public void Attrack(Monster_DI_2 monster)
        {
            Weapon.AttrackTarget(monster);
        }
    }
}
